package com.tl.boot.service.user.impl;

import com.tl.boot.entity.login.domain.LoginRecordInfo;
import com.tl.boot.entity.login.dto.LoginRecordDTO;
import com.tl.boot.entity.login.dto.ReSetPwdDTO;
import com.tl.boot.entity.permission.vo.PermissionInfoVO;
import com.tl.boot.entity.user.vo.UserBasicInfoVO;
import com.tl.boot.mapper.user.SysUserMapper;
import com.tl.boot.service.user.SysUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * com.tl.boot.service.user.impl -- SysUserServiceImpl
 * Description:
 * Created by joshua_liu <a href="mailto:joshualwork@163.com"></a>
 * On 2019/9/12 10:17
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper userMapper;

    @Override
    public UserBasicInfoVO sysUserBasicInfo(String username) {
        UserBasicInfoVO result = userMapper.sysUserBasicInfo(username);
        return result;
    }

    @Override
    public List<PermissionInfoVO> getPermissionInfo(Long userId) {
        return userMapper.getPermissionInfo(userId);
    }

    @Override
    public void addLoginRecord(LoginRecordDTO dto) {
        LoginRecordInfo loginRecordInfo = new LoginRecordInfo();
        BeanUtils.copyProperties(dto, loginRecordInfo);
        loginRecordInfo.setLoginTime(new Date(System.currentTimeMillis()));
        userMapper.addLoginRecord(loginRecordInfo);
    }

    @Override
    public void resetPwd(ReSetPwdDTO dto) {

    }
}
